package com.qiantu.phone.ui.uiutil;

import android.content.Context;

import com.qiantu.api.db.LLDeviceDBManager;
import com.qiantu.api.db.LLRoomDBManager;
import com.qiantu.api.db.LLSceneDBManager;
import com.qiantu.api.entity.DeviceBean;
import com.qiantu.api.entity.PanelBindConfig;
import com.qiantu.api.entity.SceneBean;
import com.qiantu.phone.R;

public class PanelBindConfigUIUtil {
    public DeviceBean deviceBean;
    public SceneBean sceneBean;
    public PanelBindConfig config;
    private Context mContext;

    public PanelBindConfigUIUtil(Context context, PanelBindConfig config) {
        mContext = context;
        this.config = config;
        if (config.getBindSateType() == 2){
            if (config.getBindType() == 7){
                sceneBean = LLSceneDBManager.getInstance(mContext).get(config.getBindSerialNo());
            }else {
                deviceBean = LLDeviceDBManager.getInstance(mContext).get(config.getBindSerialNo());
            }
        }
    }

    public boolean isSceneItem(){
        if (config.getBindUIType() == 5){
            return true;
        }
        return false;
    }

    public String getBindTypeStr(){
        if (config.getBindType() == 1){
            return mContext.getString(R.string.switch_light);
        }else if (config.getBindType() == 2){
            return mContext.getString(R.string.adjust_light);
        }else if (config.getBindType() == 3){
            return mContext.getString(R.string.air_conditioner);
        }else if (config.getBindType() == 4){
            return mContext.getString(R.string.fresh_air);
        }else if (config.getBindType() == 5){
            return mContext.getString(R.string.curtain);
        }else if (config.getBindType() == 6){
            return mContext.getString(R.string.adjust_color);
        }else if (config.getBindType() == 7){
            return mContext.getString(R.string.scene);
        }else if (config.getBindType() == 8){
            return mContext.getString(R.string.floor_heating);
        }else if (config.getBindType() == 9){
            return mContext.getString(R.string.two_color_tmp_ling);
        }else if (config.getBindType() == 10){
            return mContext.getString(R.string.adjust_light_color);
        }
        return "";
    }

    public int getDeviceBindType(DeviceBean deviceBean) {
        if (DeviceType.BREAKER_LIGHT.stringType.equals(deviceBean.getDeviceType())){
            return 1;
        }else if (DeviceType.ADJUST_LIGHT.stringType.equals(deviceBean.getDeviceType())){
            return 2;
        }else if (DeviceMainType.AIRCONDITIONER.stringType.equals(deviceBean.getType())){
            return 3;
        }else if (DeviceMainType.FRESHAIR.stringType.equals(deviceBean.getType())){
            return 4;
        }else if (DeviceMainType.CURTAIN.stringType.equals(deviceBean.getType())){
            return 5;
        }else if (DeviceType.ADJUST_COLOR.stringType.equals(deviceBean.getDeviceType())){
            return 6;
        }else if (DeviceMainType.FLOORHEATING.stringType.equals(deviceBean.getType())){
            return 8;
        }else if (DeviceType.TCT_DL.stringType.equals(deviceBean.getDeviceType()) || DeviceType.ADJUST_LCT.stringType.equals(deviceBean.getDeviceType())){
            return 9;
        }
        return -1;
    }

    public String getBindUITypeStr(){
        if (config.getBindUIType() == 1){
            return mContext.getString(R.string.type_light);
        }else if (config.getBindUIType() == 2){
            return mContext.getString(R.string.air_conditioner);
        }else if (config.getBindUIType() == 3){
            return mContext.getString(R.string.fresh_air);
        }else if (config.getBindUIType() == 4){
            return mContext.getString(R.string.curtain);
        }else if (config.getBindUIType() == 5){
            return mContext.getString(R.string.scene);
        }else if (config.getBindUIType() == 6){
            return mContext.getString(R.string.floor_heating);
        }
        return "";
    }

    public String getConfigItemName(){
        if (config.getBindType() == 7){
            if (sceneBean == null){
                sceneBean = LLSceneDBManager.getInstance(mContext).get(config.getBindSerialNo());
            }
            if (sceneBean !=null){
                if(sceneBean.getRoomName() == null){
                    return  mContext.getResources().getString(R.string.common) + sceneBean.getName();
                }else{
                    return sceneBean.getRoomName() + sceneBean.getName();
                }
            }
        }else {
            if (deviceBean == null){
                deviceBean = LLDeviceDBManager.getInstance(mContext).get(config.getBindSerialNo());
            }
            if (deviceBean != null){
                if(deviceBean.getRoomName() == null){
                    return mContext.getResources().getString(R.string.common) + deviceBean.getName();
                }else{
                    return deviceBean.getRoomName() + deviceBean.getName();
                }
            }
        }
        return "";
    }

    public String getConfigItemNameWithFloor(){
        if (config.getBindType() == 7){
            if (sceneBean == null){
                sceneBean = LLSceneDBManager.getInstance(mContext).get(config.getBindSerialNo());
            }
            if (sceneBean !=null){
                return LLRoomDBManager.getInstance(mContext).getFloorRoomName(sceneBean.getRoomSerialNo());
            }
        }else {
            if (deviceBean == null){
                deviceBean = LLDeviceDBManager.getInstance(mContext).get(config.getBindSerialNo());
            }
            if (deviceBean != null){
                 return LLRoomDBManager.getInstance(mContext).getFloorRoomName(deviceBean.getRoomSerialNo());
            }
        }
        return "";
    }

    public String getDeviceMainType() {
        if (config.getBindUIType() == 1){
            return DeviceMainType.LIGHT.stringType;
        }else if (config.getBindUIType() == 2){
            return DeviceMainType.AIRCONDITIONER.stringType;
        }else if (config.getBindUIType() == 3){
            return DeviceMainType.FRESHAIR.stringType;
        }else if (config.getBindUIType() == 4){
            return DeviceMainType.CURTAIN.stringType;
        }else if (config.getBindUIType() == 5){
            return "";
        }else if (config.getBindUIType() == 6){
            return DeviceMainType.FLOORHEATING.stringType;
        }
        return "";
    }
}
